package com.weaver.openapi.service;

import com.weaver.openapi.pojo.blog.params.*;
import com.weaver.openapi.util.*;
import java.util.*;
import cn.hutool.http.*;
import com.alibaba.fastjson.*;
import com.weaver.openapi.pojo.blog.res.*;
import com.weaver.openapi.pojo.*;

public class BlogService
{
    public static BlogCreateVo createBlogV2(final BlogVo blogVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", blogVo.getAccessToken());
        paramMap.put("userid", blogVo.getUserid());
        paramMap.put("blogTime", blogVo.getBlogTime());
        paramMap.put("content", blogVo.getContent());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/blog/v2/createBlog").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (BlogCreateVo)JSONObject.parseObject(resJson, (Class)BlogCreateVo.class);
    }
    
    public static MessageResult updateBlogV2(final BlogVo blogVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", blogVo.getAccessToken());
        paramMap.put("userid", blogVo.getUserid());
        paramMap.put("blogId", blogVo.getBlogId());
        paramMap.put("blogTime", blogVo.getBlogTime());
        paramMap.put("content", blogVo.getContent());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/blog/v2/updateBlog").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return (MessageResult)JSONObject.parseObject(resJson, (Class)MessageResult.class);
    }
    
    public static NormalRes<BlogQueryVo> queryBlogV2(final BlogVo blogVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", blogVo.getAccessToken());
        paramMap.put("userIds", blogVo.getUserIds());
        paramMap.put("startDate", blogVo.getStartDate());
        paramMap.put("endDate", blogVo.getEndDate());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/blog/v2/queryBlog").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<BlogQueryVo> queryBlogStatisticV2(final BlogVo blogVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", blogVo.getAccessToken());
        paramMap.put("userIds", blogVo.getUserIds());
        paramMap.put("startDate", blogVo.getStartDate());
        paramMap.put("endDate", blogVo.getEndDate());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/blog/v2/queryBlogStatistic").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<BlogQueryVo> queryDateBlogV2(final BlogVo blogVo, String host, final Map<String, String> headers) {
        host = HostUtil.beforeRequestCheckHeaders(host, headers, "application/x-www-form-urlencoded");
        final Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("access_token", blogVo.getAccessToken());
        paramMap.put("startDate", blogVo.getStartDate());
        paramMap.put("endDate", blogVo.getEndDate());
        paramMap.put("queryType", blogVo.getQueryType());
        final String resJson = ((HttpRequest)HttpRequest.post(host + "/blog/v2/queryDateBlog").form((Map)paramMap).headerMap((Map)headers, true)).execute().body();
        return transferResult(resJson);
    }
    
    public static NormalRes<BlogQueryVo> transferResult(final String resJson) {
        final JSONObject jsonObject = JSONObject.parseObject(resJson);
        final BlogQueryVo data = (BlogQueryVo)jsonObject.getObject("data", (Class)BlogQueryVo.class);
        final NormalResult message = (NormalResult)jsonObject.getObject("message", (Class)NormalResult.class);
        final NormalRes<BlogQueryVo> normalRes = new NormalRes<BlogQueryVo>();
        normalRes.setData(data);
        normalRes.setMessage(message);
        return normalRes;
    }
}
